var Api = require('../../utils/api.js');
var app = getApp();
var search;
Page({
  onLoad: function (reload = false) {
    this.init();
  },
  data: {
    is_onload:false,
    keywords:"",
    conference_id:"",
    meeting_type:true,
    agenda_list: [
      {//一个小会
        time: '09:00-10:00',
        agenda_title: 'STEM教育在中国独特的商业发展思路',
        agenda_people: [
          {
            identity: '',
            name: '邱彦峰 鲨鱼公司董事长',
            avatar: '/image/ai.png',
          }
        ],
      },
      {//一个小会
        time: '09:00-10:00',
        agenda_title: '圆桌分享',
        agenda_people: [
          {
            identity: '圆桌主持：',
            name: '邱彦峰 鲨鱼公司董事长',
            avatar: '/image/comment_1.png',
          },
          {
            identity: '圆桌嘉宾：',
            name: '邱彦峰 鲨鱼公司董事长',
            avatar: '/image/ai.png',
          },
          {
            identity: '',
            name: '邱彦峰 鲨鱼公司董事长',
            avatar: '/image/ai.png',
          }
        ],
      },
    ],
  },
  onLoad: function (options) {
    var keywords = options.search; 
    var conference_id = options.conference_id;
    this.setData({
      keywords: keywords,
      conference_id: conference_id,
    });
    this.init();
  },
  init: function () {
    wx.showToast({
      title: '加载中...',
      icon: 'loading',
      duration: 10000
    });
    this.initSearch({
      keywords: this.data.keywords,
      conference_id: this.data.conference_id,
    });
  },
  onShow: function () {
    this.initSearch({
      keywords: this.data.keywords,
      conference_id: this.data.conference_id,
    });
  },
  initSearch: function (o) {
    var that = this;
    wx.request({
      url: Api.searchAgenda(o),
      header: {
        'content-type': 'application/json'
      }, // 设置请求的 header
      success: function (res) {

        that.setData({
          is_onload:true,
          agenda_list:res.data.agenda_list,
          count: res.data.count
        });

        that.update();
        wx.hideToast();
        wx.stopPullDownRefresh({
          complete: function (res) {
            console.log(res, new Date())
          }
        });
      },
      fail: function () {
        
      },
      complete: function () {
        // complete
      }
    });
  },
  // 键盘点击完成时触发
  searchAgenda: function (e) {
    var that = this;
    search = e.detail.value
    if (e.detail.value.length < 1) {
      wx.showModal({
        title: '提示',
        content: '当前搜索框内容为空，是否重新输入？',
        success: function (res) {
          if (res.confirm) {
            that.setData({
              focus: true
            })
          }
        },
        fail: function () {
          wx.hideToast();
        },
        complete: function () {
          wx.hideToast();
        }
      })
    } else {
      this.setData({
        keywords: search
      });
      that.init();
    }
  },
  clear: function () {

  },
  onPullDownRefresh: function () {

  },
  stopPullDownRefresh: function () {

  }
})
